<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.7.0/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.7.0/themes/icon.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.7.0/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.7.0/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.7.0/jquery.easyui.min.js"></script>

<script type="text/javascript">
	var url;
	 function searchUser(){
		$("#dg").datagrid('load',{
			"indiId":$("#s_indiId").val() 
		});
		
	 }
	 function openUserAddDialog(){
		$("#dlg").dialog("open").dialog("setTitle","添加指标");
		url="${pageContext.request.contextPath}/interactive/getIndiObject"
	}
	 function openUserModifyDialog(){ //修改和查询对应一个table
		var selectedRows=$("#dg").datagrid("getSelections");//返回的是一个集合数组 
		if(selectedRows.length!=1){
			$.messager.alert("系统提示","请选择一条要编辑的数据！");
			return;
		}
		//只有一个字段删除添加就行
		var row=selectedRows[0];//获取一条数据修改
		$("#dlg").dialog("open").dialog("setTitle","编辑指标信息");
		$("#fm").form("load",row);//加载所有字段信息
		//url="${pageContext.request.contextPath}/userController/saveUser.do?id="+row.id;
	 }
	
	 function saveUser(){
		$("#fm").form("submit",{
			url:url,
			onSubmit:function(){
				return $(this).form("validate");
			},
			success:function(result){
				var result=eval('('+result+')');
				if(result.success){
					$.messager.alert("系统提示","保存成功！");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败！");
					return;
				}
			}
		});
	 }
	 
	 function resetValue(){
		$("#id").val("");
	 }
	 
	 function closeUserDialog(){
		$("#dlg").dialog("close");
		resetValue();
	 }
	 
	 function deleteUser(){
		var selectedRows=$("#dg").datagrid("getSelections");
		if(selectedRows.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		var strIds=[];
		for(var i=0;i<selectedRows.length;i++){
			strIds.push(selectedRows[i].id);
		}
		var ids=strIds.join(",");
		$.messager.confirm("系统提示","您确定要删除这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
			if(r){
				$.post("${pageContext.request.contextPath}/userController/deleteUser.do",{ids:ids},function(result){
					if(result.success){
						$.messager.alert("系统提示","数据已成功删除！");
						$("#dg").datagrid("reload");
					}else{
						$.messager.alert("系统提示","数据删除失败，请联系系统管理员！");
					}
				},"json");
			} 
		});
	 }
</script>
<title>Insert title here</title>
</head>
<body style="margin: 1px">
<!-- pagination="true" rownumbers="true" 设置就是分页 设置他即可 -->
 <table id="dg" title="指标管理" class="easyui-datagrid"
   fitColumns="true" pagination="true" rownumbers="true"
   url="${pageContext.request.contextPath}/userController/list.do"  fit="true" toolbar="#tb">
   <thead>
    <tr>
    <th field="cb" checkbox="true" align="center"></th>
    <th field="id" width="50" align="center">指标编号</th>
    </tr>
   </thead>
 </table>
 <div id="tb">
  <div>
  <a href="javascript:openUserAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
  <a href="javascript:openUserModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
  <a href="javascript:deleteUser()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
  </div>
  <div><!-- event.keyCode==13 是按了enter键 -->
  &nbsp;指标编号：&nbsp;<input type="text" id="s_indiId" size="20" onkeydown="if(event.keyCode==13) searchUser()"/>
  <a href="javascript:searchUser()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
  </div>
 </div>
 <div id="dlg" class="easyui-dialog" style="width:620px;height:250px;padding: 10px 20px;"
    closed="true" buttons="#dlg-buttons">
    
   <form id="fm" method="post">
    <table cellspacing="8px">
    <tr>
    <td>指标编号：</td>
    <td><input type="text" id="indiId" name="indiId" class="easyui-validatebox" required="true"/>&nbsp;<font color="red">*</font></td>
    </tr>
    </table>
   </form>
 </div>
 
 <div id="dlg-buttons">
  <a href="javascript:saveUser()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
  <a href="javascript:closeUserDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
 </div>
</body>
</html>